/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interceptor;

import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import java.util.Map;

/**
 *
 * @author xiaoxiao
 */
public class loginInterceptor extends AbstractInterceptor {

    public loginInterceptor() {
    }

    public void destroy() {
    }

    public void init() {
    }

    public String intercept(ActionInvocation ai) throws Exception {
        ActionContext ctx=ai.getInvocationContext();
        Map session=ctx.getSession();
        String username=(String)session.get("username");
        if(username !=null && username.length()>0)
        {
            return ai.invoke();
        }else
        {
            ctx.put("tip", "请先登录！");
            return Action.LOGIN;
        }
    }
}
